<?php
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/Account.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/HumeurDatabase.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/includes/sugar.php");
	session_start();
	$db = new HumeurDatabase();
	if(mysql_num_rows($db->query("SELECT * FROM accounts WHERE isAdmin = '1';")) > 1){
		$disabledAccount = new Account($_POST['mail']);
		$disabledAccount->toggleAdmin();
		if($disabledAccount->save()){
			$array['errMess'] = getErrMess(25);
			$array['status'] = 1;
			$_SESSION['account']->load($_SESSION['account']->mail);
		}
		else
		{
			$array['errMess'] = getErrMess(24);
			$array['status'] = 0;
		}
		$array['mail'] = $_POST['mail'];
	}
	else
	{
		$array['errMess'] = getErrMess(26);
		$array['status'] = 0;
		$array['mail'] = "";
	}
	echo json_encode($array);
?>